/* send/recieve data to/from vvvvv
 * -----------
 *
 * poti --> arduino --> vvvv --> arduino --> control LED 
 * 17-01-2006
 * copyleft 2006 benedikt gross 
 * <http://www.looksgood.de>
*/

int potPin = 5;        // select the input pin for the potentiometer
int ledPin = 13;       // select the pin for the LED
int val,serialGet = 0; // variable to store the value coming from the sensor/serial port (from vvvv)
int delaytime = 1;     // delay time for the main loop


void setup() {
  pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT
  beginSerial(9600);        // use the serial port to send/recieve values to/from the computer
}

void loop() {
  val = analogRead(potPin);    // read the value from the potentiometer

  printInteger(val);           // print the value to the serial port
  //linebreak
  serialWrite(10); 
  serialWrite(13);  

  // read the serial port
  serialGet = serialRead();

  // if the input is '-1' then there is no data
  // at the input, otherwise store it  
  if (serialGet != -1) {
    val = serialGet;
  }

  // if the stored value is 'H' turn the LED on
  // if the stored value is 'L' turn the LED off
  if (val == 'H') {
    digitalWrite(ledPin, HIGH);
  } 
  else if (val == 'L') {
    digitalWrite(ledPin, LOW);
  }

  delay(delaytime);  

}
